/*
 * Copyright (c) 2018-2999 九五云信息科技有限公司 All rights reserved.
 *
 * https://www.gz-yami.com/
 *
 * 未经允许，不可做商业用途！
 *
 * 版权所有，侵权必究！
 */

package com.yami.shop.service;

import com.alipay.api.AlipayApiException;
import com.github.binarywang.wxpay.exception.WxPayException;
import com.yami.shop.bean.bo.PayInfoBo;
import com.yami.shop.bean.bo.RefundInfoBo;
import com.yami.shop.bean.model.Order;
import com.yami.shop.bean.model.OrderSettlement;
import com.yami.shop.bean.pay.PayInfoDto;
import com.yami.shop.bean.pay.RefundInfoDto;
import com.yami.shop.common.enums.PayType;
import org.springframework.http.ResponseEntity;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.List;

/**
 * 支付相关
 */
public interface PayManagerService {


	/**
	 * 进行支付
	 * @param httpResponse
	 * @param payInfo
	 * @return
	 * @throws WxPayException
	 * @throws IOException
	 */
	ResponseEntity<?> doPay(HttpServletResponse httpResponse, PayInfoDto payInfo) throws WxPayException, IOException, AlipayApiException;


	/**
	 * 校验支付结果，并返回支付单号
	 * @param request
	 * @param payType
	 * @param xmlData
	 * @return
	 * @throws UnsupportedEncodingException
	 * @throws WxPayException
	 * @throws AlipayApiException
	 */
	PayInfoBo validateAndGetPayInfo(HttpServletRequest request, PayType payType, String xmlData) throws UnsupportedEncodingException, WxPayException, AlipayApiException;


	/**
	 * 主动查单，看看订单是否已经支付
	 * @param payNo 支付单号
	 * @return
	 */
	PayInfoBo getPayInfo(PayType payType,String payNo);


	/**
	 * 退款
	 */
	boolean doRefund(RefundInfoDto refundInfo);

	/**
	 * 取消用二维码支付的订单时一并失效掉对应二维码
	 * @param orderSettlements 订单支付信息
	 * @return 结果
	 */
	Boolean cancelOrderQrCode(List<OrderSettlement> orderSettlements) throws WxPayException,AlipayApiException;



	/**
	 * 校验支付结果，并返回支付单号
	 * @param request
	 * @param payType
	 * @param xmlData
	 * @return
	 * @throws UnsupportedEncodingException
	 * @throws WxPayException
	 * @throws AlipayApiException
	 */
	RefundInfoBo validateAndGetRefundInfo(HttpServletRequest request, PayType payType, String xmlData) throws UnsupportedEncodingException, WxPayException, AlipayApiException;

}
